package fr.umlv.m2.jee.spij.persistence.education;

import fr.umlv.m2.jee.spij.persistence.actor.StudentPartial;
import fr.umlv.m2.jee.spij.persistence.actor.TeacherPartial;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Entity Partial who contain information about partial.
 *
 * @author Lounes Akroune
 * @author Aurelien Scelles
 */
@Entity
@Table(name = "PAR_PARTIAL")
public class Partial extends Exam {

    /**
     * Primary key.
     */
    @Id
    @Column(name = "PAR_ID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    /**
     * Partial's Correction.
     */
    @Lob
    @Column(name = "PAR_CORRECTION")
    private String correction;

    /**
     * Link of Partial's Correction in PDF.
     */
    @Column(name = "PAR_LINK_CORRECTION")
    private String linkCorrection;

    /**
     * Partial's Date.
     *
     * @see org.joda.time.contrib.hibernate.PersistentDateTime
     */
    @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
    @Column(name = "PAR_DATE")
    private DateTime date;

    /**
     * Consultation's Date.
     *
     * @see org.joda.time.contrib.hibernate.PersistentDateTime
     */
    @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
    @Column(name = "PAR_CONSULTATION")
    private DateTime consultation;

    /**
     * Id of linked unit.
     */
    @Column(name = "PAR_UNI_ID")
    private Long unit;


    /**
     * List of students
     */
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "SP_PARTIAL_ID", referencedColumnName = "PAR_ID")
    private List<StudentPartial> students = new ArrayList<StudentPartial>();

    /**
     * List of teachers
     */
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "TP_PARTIAL_ID", referencedColumnName = "PAR_ID")
    private List<TeacherPartial> teachers = new ArrayList<TeacherPartial>();

    /**
     * Setter of Date.
     *
     * @param date
     */
    public void setDate(DateTime date) {
        this.date = date;
    }

    /**
     * Getter of Date.
     *
     * @return partial's date
     */
    public DateTime getDate() {
        return date;
    }

    /**
     * Setter of Consultation.
     *
     * @param consultation
     */
    public void setConsultation(DateTime consultation) {
        this.consultation = consultation;
    }

    /**
     * Getter of Consultation.
     *
     * @return Consultation's Date
     */
    public DateTime getConsultation() {
        return consultation;
    }

    /**
     * Setter of Correction.
     *
     * @param correction
     */
    public void setCorrection(String correction) {
        this.correction = correction;
    }

    /**
     * Getter of Correction.
     *
     * @return correction
     */
    public String getCorrection() {
        return correction;
    }

    /**
     * Setter of linkCorrection.
     *
     * @param linkCorrection
     */
    public void setLinkCorrection(String linkCorrection) {
        this.linkCorrection = linkCorrection;
    }

    /**
     * Getter of linkCorrection.
     *
     * @return the link of Correction in PDF
     */
    public String getLinkCorrection() {
        return linkCorrection;
    }

    /**
     * Setter of id.
     *
     * @param id
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * Getter of id.
     *
     * @return primary key
     */
    public long getId() {
        return id;
    }

    /**
     * Setter of unit.
     *
     * @param unit
     */
    public void setUnit(Long unit) {
        this.unit = unit;
    }

    /**
     * Getter of unit.
     *
     * @return id of linked unit
     */
    public Long getUnit() {
        return unit;
    }

    public void setStudents(List<StudentPartial> students) {
        this.students = students;
    }

    public List<StudentPartial> getStudents() {
        return students;
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#add(java.lang.Object)
     */
    public boolean addStudent(StudentPartial arg0) {
        return students.add(arg0);
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#get(int)
     */
    public StudentPartial getStudent(int arg0) {
        return students.get(arg0);
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#remove(java.lang.Object)
     */
    public boolean removeStudent(Object arg0) {
        return students.remove(arg0);
    }

    /**
     * @return
     *
     * @see java.util.List#size()
     */
    public int numberOfStudents() {
        return students.size();
    }

    public void setTeachers(List<TeacherPartial> teachers) {
        this.teachers = teachers;
    }

    public List<TeacherPartial> getTeachers() {
        return teachers;
    }

    /**
     * @param e
     *
     * @return
     *
     * @see java.util.List#add(java.lang.Object)
     */
    public boolean addTeacher(TeacherPartial e) {
        return teachers.add(e);
    }

    /**
     * @param index
     *
     * @return
     *
     * @see java.util.List#get(int)
     */
    public TeacherPartial getTeacher(int index) {
        return teachers.get(index);
    }

    /**
     * @param o
     *
     * @return
     *
     * @see java.util.List#remove(java.lang.Object)
     */
    public boolean removeTeacher(Object o) {
        return teachers.remove(o);
    }

    /**
     * @return
     *
     * @see java.util.List#size()
     */
    public int numberOfTeachers() {
        return teachers.size();
    }
}
